package net.alche.fa.core.doing.invoker;

import net.alche.fa.core.doing.FaAnnoDoing;
import net.alche.fa.core.model.FaValue;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.alche.fa.core.FaException;
import net.alche.al.util.AC;

@FaAnnoDoing
@SuppressWarnings("all")
public class FaMapEntryInvoker extends AbstractObjectInvoker {
  // 是否为此对象
  public boolean matched(FaValue objVal, Object obj, String methodName, List<FaValue> params) {
    if (obj instanceof Map.Entry) {
      return true;
    }
    return false;
  }

  // 调用
  public FaValue invoke(FaValue objVal, Object obj, String methodName, List<FaValue> params) throws FaException {
    Map.Entry map = (Map.Entry) obj;
    FaValue first = null;
    if (params != null && !params.isEmpty()) {
      first = params.get(0);
    }
    switch (methodName) {
      case "getKey": {
        return new FaValue(map.getKey());
      }
      case "getValue": {
        return new FaValue(map.getValue());
      }
      default: {
        throw new FaException(FaException.LESS_METHOD, "fa-map method not find | method = " + methodName,
            "params=" + AC.json.toStr(params));
      }
    }
  }
}
